#include "stdafx.h"
#include <boost/test/auto_unit_test.hpp>
#include <sstream>
#include "detail/bmock_out_str_arg_val.hpp"
#include "detail/bmock_test_control_tools.hpp"
#include "bmock_util.hpp"

namespace bmock {
	static const control_tools_ptr tl(new test_control_tools());
	static const char              name[]   = "arg";
	static const unsigned char     s_val1[] = {0x81,0x82,0x83,0x84,0x85,0x00};
	static const size_t            LEN      = sizeof(s_val1);

	BOOST_AUTO_TEST_CASE(test_out_unsigned_str_arg_val_get_value) {
		const arg_val_ptr p_val(make_out_arg_val(name,(unsigned char *)s_val1));
		arg_checker       al(tl);
		const arg_val_str expected("",(const char *)s_val1);

		BOOST_CHECK_EQUAL(expected,p_val->get_value(al));
	}

	BOOST_AUTO_TEST_CASE(test_out_unsigned_str_arg_val_update) {
		unsigned char     s_val2[LEN];
		const arg_val_ptr p_val(make_out_arg_val(name,s_val2));
		arg_checker       al(tl);
		const arg_val_str expected("",(const char *)s_val1);

		al.set_location(location(__FILE__,__LINE__+1));
		BOOST_CHECK_NO_THROW(p_val->update(al,expected));
		BOOST_CHECK_EQUAL(LEN,mismatch_at(s_val1,s_val1+LEN,s_val2));
	}

	BOOST_AUTO_TEST_CASE(test_out_unsigned_str_arg_val_print) {
		unsigned char     s_val2[sizeof(s_val1)];
		const arg_val_ptr p_val(make_out_arg_val(name,s_val2));
		const std::string      expected = std::string("OUT(")+out_arg_val::UNKNOWN+")";
		std::ostringstream        os;

		strcpy((char *)s_val2,(const char *)s_val1);
		BOOST_CHECK_NO_THROW(p_val->print(os));
		BOOST_CHECK_EQUAL(expected,os.str());
	}
}
